
const connect = {
    orm: function(){
        const dbConfig = require("./dbconfig")
        const Sequelize = require('sequelize')
        const sequelize = new Sequelize(dbConfig.database,dbConfig.user, dbConfig.password, {
                host: dbConfig.host,
                dialect: 'mysql',
                dialectOptions: {connectTimeout: 5000}, // mariadb connector option
                pool: {                 // 使用连接池
                    max: 5,
                    min: 0,
                    acquire: 30000,
                    idle: 10000,
                },
                logging: (msg) => {
                    console.log('msg', msg);
                },
                timezone: '+08:00',
            }
        );
        sequelize.authenticate()
            .then(() => {
                console.log('Connection has been established successfully.');
            }).catch(err => {
            console.error('Unable to connect to the database:', err);
        });
        return sequelize
    }
}

  module.exports = connect
